Skip to content

fix(builtins): clear variable on read at EOF with no remaining data#976

Merged
chaliy merged 1 commit intomainfrom
fix/issue-953-read-eof-clear
Apr 2, 2026
Merged

fix(builtins): clear variable on read at EOF with no remaining data#976
chaliy merged 1 commit intomainfrom
fix/issue-953-read-eof-clear

Conversation

@chaliy
Copy link
Copy Markdown
Contributor

@chaliy chaliy commented Apr 2, 2026

Summary

  • Fix read at EOF retaining the last value instead of clearing the variable
  • When read reaches EOF with no data, now clears target variables to empty before returning 1
  • Prevents the common while read line || [[ -n "$line" ]] pattern from infinite looping

What

The read builtin returned ExecResult::err("", 1) on EOF without any SetVariable side effects, so the variable kept its previous value. Now the EOF path parses flag arguments first, then emits SetVariable side effects with empty values for all target variables.

Test plan

  • New spec test: read_eof_clears_variable — verifies printf "one\ntwo" loop terminates
  • New spec test: read_eof_partial_line — verifies partial line without trailing newline is captured
  • All existing read-builtin spec tests pass
  • Manual smoke test confirms no infinite loop

Closes #953

When read reaches EOF and there is no partial line data remaining,
clear the target variable to empty string before returning 1. This
prevents the common `while read line || [[ -n "$line" ]]` pattern
from looping infinitely on the stale last value.

Closes #953
@chaliy chaliy merged commit 04d8aa1 into main Apr 2, 2026
27 checks passed
@chaliy chaliy deleted the fix/issue-953-read-eof-clear branch April 2, 2026 06:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

read at EOF retains last value instead of clearing variable, causing infinite loops

1 participant